package com.example.dyxeapplication.menu.cerita;

import com.example.dyxeapplication.R;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

public class Menu_Cerita extends FragmentActivity {

	/**
	 * The {@link android.support.v4.view.PagerAdapter} that will provide
	 * fragments for each of the sections. We use a
	 * {@link android.support.v4.app.FragmentPagerAdapter} derivative, which
	 * will keep every loaded fragment in memory. If this becomes too memory
	 * intensive, it may be best to switch to a
	 * {@link android.support.v4.app.FragmentStatePagerAdapter}.
	 */
	SectionsPagerAdapter mSectionsPagerAdapter;

	/**
	 * The {@link ViewPager} that will host the section contents.
	 */
	ViewPager mViewPager;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.menu_cerita_tab);

		// Create the adapter that will return a fragment for each of the three
		// primary sections of the app.
		mSectionsPagerAdapter = new SectionsPagerAdapter(
				getSupportFragmentManager());

		// Set up the ViewPager with the sections adapter.
		mViewPager = (ViewPager) findViewById(R.id.pager);
		mViewPager.setAdapter(mSectionsPagerAdapter);

	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}

	/**
	 * A {@link FragmentPagerAdapter} that returns a fragment corresponding to
	 * one of the sections/tabs/pages.
	 */
	public class SectionsPagerAdapter extends FragmentPagerAdapter {

		public SectionsPagerAdapter(FragmentManager fm) {
			super(fm);
		}

		@Override
		public Fragment getItem(int position) {
			// getItem is called to instantiate the fragment for the given page.
			// Return a DummySectionFragment (defined as a static inner class
			// below) with the page number as its lone argument.
			Fragment fragment = new DummySectionFragment();
			Bundle args = new Bundle();
			args.putInt(DummySectionFragment.ARG_SECTION_NUMBER, position);
			fragment.setArguments(args);
			return fragment;
		}

		@Override
		public int getCount() {
			// Show 13 total pages.
			return 13;
		}

		@Override
		public CharSequence getPageTitle(int position) {
			switch (position) {
			case 0:
				return getString(R.string.title_section0);
			case 1:
				return getString(R.string.title_section1);
			case 2:
				return getString(R.string.title_section2);
			case 3:
				return getString(R.string.title_section3);
			case 4:
				return getString(R.string.title_section4);
			case 5:
				return getString(R.string.title_section5);
			case 6:
				return getString(R.string.title_section6);
			case 7:
				return getString(R.string.title_section7);
			case 8:
				return getString(R.string.title_section8);
			case 9:
				return getString(R.string.title_section9);
			case 10:
				return getString(R.string.title_section10);
			case 11:
				return getString(R.string.title_section11);
			case 12:
				return getString(R.string.title_section12);
			}
			return null;
		}
	}

	/**
	 * A dummy fragment representing a section of the app, but that simply
	 * displays dummy text.
	 */
	public static class DummySectionFragment extends Fragment {
		/**
		 * The fragment argument representing the section number for this
		 * fragment.
		 */
		public static final String ARG_SECTION_NUMBER = "section_number";

		public DummySectionFragment() {
		}

		// put all the mp3 filename as String array
		private ImageView imgview;
		private View rootView;
		// get the current screen number
		private int skrinno;

		// admob id - a1501b1ff3dd2d0

		@Override
		public View onCreateView(LayoutInflater inflater, ViewGroup container,
				Bundle savedInstanceState) {
			rootView = inflater.inflate(R.layout.menu_cerita_fragment,
					container, false);
			skrinno = getArguments().getInt(ARG_SECTION_NUMBER);

			// set the screen image
			imgview = (ImageView) rootView.findViewById(R.id.imgnumber);
			if (skrinno == 0) {
				Bitmap bMap = BitmapFactory.decodeResource(getResources(),
						R.drawable.cerita1);
				imgview.setImageBitmap(bMap);
			} else if (skrinno == 1) {
				Bitmap bMap = BitmapFactory.decodeResource(getResources(),
						R.drawable.cerita2);
				imgview.setImageBitmap(bMap);
			} else if (skrinno == 2) {
				Bitmap bMap = BitmapFactory.decodeResource(getResources(),
						R.drawable.cerita3);
				imgview.setImageBitmap(bMap);
			} else if (skrinno == 3) {
				Bitmap bMap = BitmapFactory.decodeResource(getResources(),
						R.drawable.cerita4);
				imgview.setImageBitmap(bMap);
			} else if (skrinno == 4) {
				Bitmap bMap = BitmapFactory.decodeResource(getResources(),
						R.drawable.cerita5);
				imgview.setImageBitmap(bMap);
			} else if (skrinno == 5) {
				Bitmap bMap = BitmapFactory.decodeResource(getResources(),
						R.drawable.cerita6);
				imgview.setImageBitmap(bMap);
			} else if (skrinno == 6) {
				Bitmap bMap = BitmapFactory.decodeResource(getResources(),
						R.drawable.cerita7);
				imgview.setImageBitmap(bMap);
			} else if (skrinno == 7) {
				Bitmap bMap = BitmapFactory.decodeResource(getResources(),
						R.drawable.cerita8);
				imgview.setImageBitmap(bMap);
			} else if (skrinno == 8) {
				Bitmap bMap = BitmapFactory.decodeResource(getResources(),
						R.drawable.cerita9);
				imgview.setImageBitmap(bMap);
			} else if (skrinno == 9) {
				Bitmap bMap = BitmapFactory.decodeResource(getResources(),
						R.drawable.cerita10);
				imgview.setImageBitmap(bMap);
			} else if (skrinno == 10) {
				Bitmap bMap = BitmapFactory.decodeResource(getResources(),
						R.drawable.cerita11);
				imgview.setImageBitmap(bMap);
			} else if (skrinno == 11) {
				Bitmap bMap = BitmapFactory.decodeResource(getResources(),
						R.drawable.cerita12);
				imgview.setImageBitmap(bMap);
			} else if (skrinno == 12) {
				Bitmap bMap = BitmapFactory.decodeResource(getResources(),
						R.drawable.cerita13);
				imgview.setImageBitmap(bMap);
			}
			return rootView;
		}
	}

}
